//
//  YiTypeListView.swift
//  yiplayer
//
//  Created by wkun on 2024/6/14.
//

import Foundation
class YiTypeListView : YiListView{
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.navView.rightBtn.isHidden = true 
        self.navView.titleL.text = "选择协议"
        
        self.registerCell()
        self.loadDatas()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func loadDatas() {
        var ar = [YiListViewCellModel]()
        let nas = ["WebDav", "FTP", "SMB"]
        let imgs = ["net_dav","net_ftp","net_smb"]
        let tys: [ServerType] = [.webdav, .ftp, .smb]
        for i in 0..<nas.count {
            let m = YiServerListCellModel()
            m.text = nas[i]
            m.imgname = imgs[i]
            m.type = tys[i]
            ar.append(m)
        }
        self.datas = ar
        self.tableView.reloadData()
    }
    
    // MARK: - TouchEvents
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        super.tableView(tableView, didSelectRowAt: indexPath)
        
        if let m = self.model(datas, indexPath) as? YiServerListCellModel {
            let lv = YiAddServerListView()
            lv.type = m.type
            self.currCtrl()?.addListView(lv)
        }
    }
}
